package module.building.view.buildingListPanel
{
	import com.darwin.darwinUI.assist.Group;
	import com.darwin.darwinUI.assist.IGroupItem;
	import com.darwin.darwinUI.controls.Button;
	import com.darwin.darwinUI.controls.LabelButton;
	import com.darwin.darwinUI.core.UIComponent;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	import module.main.view.ResourceConst;
	
	/**
	 *建筑选项卡的项目 
	 * @author hc
	 */
	public class BuildTab extends LabelButton implements IGroupItem
	{
		private var _type:int;
		private var _group:Group;
		private var _autoSelectSubTab:SubBuildTab;
		
		/**
		 * 构造方法 
		 * @param type 建筑大类：0是生产；1是商业；2是扩展设施；3是民居；4是装饰；5是城市功能；6是军事
		 * 
		 */
		public function BuildTab(type:int)
		{
			super();
			_type = type;
			init();
			addEventListener(Event.ADDED_TO_STAGE, onAdded);
		}
		
		private function init():void
		{
			this.backgroundAuto = true;
			this.backgroundSkin = ResourceConst.BUILD_IMAGE_TAB_BG;
			this.autoSize = true;
			
			var icon:UIComponent = new UIComponent();
			icon.backgroundAuto = true;
			addChild(icon);
			
			switch(_type)
			{
				case 0:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_BUILD;
					this.text = "生产";
					icon.x = -17.6;
					icon.y = -0.85;
					break;
				case 1:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_GATE;
					this.text = "商业";
					icon.x = -15.85;
					icon.y = -1.85;
					break;
				case 2:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_DECORATION;
					this.text = "扩展设施";
					icon.x = -11.15;
					icon.y = -3.35;
					break;
				case 3:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_DECORATION;
					this.text = "民居";
					icon.x = -11.15;
					icon.y = -3.35;
					break;
				case 4:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_DECORATION;
					this.text = "装饰";
					icon.x = -11.15;
					icon.y = -3.35;
					break;
				case 5:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_DECORATION;
					this.text = "城市功能";
					icon.x = -11.15;
					icon.y = -3.35;
					break;
				case 6:
					icon.backgroundSkin = ResourceConst.BUILD_ICON_DECORATION;
					this.text = "军事";
					icon.x = -11.15;
					icon.y = -3.35;
					break;
				default:
					break;
			}
			
			this.textX = (background.width-textWidth)/2;//24.35;
			this.textY = 3;
		}
		
		private function onAdded(e:Event):void
		{
//			addEventListener(MouseEvent.MOUSE_OVER, onMouseOverH);
//			addEventListener(MouseEvent.MOUSE_OUT, onMouseOutH);
//			addEventListener(MouseEvent.CLICK, onClick);
		}
		
		override public function onMouseOver():void
		{
//			filters = [FILTER];
		}
		
		override public function onMouseOut():void
		{
			filters = [];
		}
		
		override public function onClick():void
		{
			trace("click "+text);
			if(group)
			{
				group.itemSelectActionStart(this,true);			
			}
		}

		public function get group():Group
		{
			return _group;
		}

		public function set group(value:Group):void
		{
			_group = value;
		}

		public function set immediateSelected(value:Boolean):void
		{
			
		}
		
		public function selectAction(selected:Boolean):void
		{
			if(selected)
			{
				MovieClip(this.background).gotoAndStop(2);
				textX = (background.width-textWidth)/2+0.5;
				textY = 3.5;
//				textColor = 0xffffff;
			}
			else
			{
				MovieClip(this.background).gotoAndStop(1);
				textX = (background.width-textWidth)/2;
				textY = 3;
//				textColor = 0;
			}
			if(group)
			{
				group.itemSelectActionEnd(this,selected);
			}
		}
		
		public function groupSelectionChange(curruntSelection:IGroupItem):void
		{
			
		}

		public function get type():int
		{
			return _type;
		}

		public function get autoSelectSubTab():SubBuildTab
		{
			return _autoSelectSubTab;
		}

		public function set autoSelectSubTab(value:SubBuildTab):void
		{
			_autoSelectSubTab = value;
		}


	}
}